package interview.huawei.tjt.training.huaweijishi;

import java.util.*;

public class Demo {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNextLine()) {
            String[] strings = scanner.nextLine().split(",");
            if (strings.length != 4) {
                System.out.println("-1");;
            }
            int count25 = 0;
            int count69 = 0;
            for (int i = 0; i < strings.length - 1; i ++) {
                for (int j = i + 1; j < strings.length; j ++) {
                    if ( strings[i] == strings[j] ) {
                        System.out.println("-1");
                    }
                }
            }

            Set<Integer> set = new TreeSet<>();

            for (int i = 0; i < strings.length; i ++) {
                set.add(Integer.parseInt(strings[i]));
                if (Integer.parseInt(strings[i]) == 2 || Integer.parseInt(strings[i]) == 5) {
                    count25 ++;
                } else if (Integer.parseInt(strings[i]) == 6 || Integer.parseInt(strings[i]) == 9) {
                    count69 ++;
                } else if (Integer.parseInt(strings[i]) <= 0 || Integer.parseInt(strings[i]) >= 10) {
                    System.out.println("-1");
                }
            }
            if (count25 > 1 || count69 > 1) {
                System.out.println("-1");
            }

            for ( int i : set) {
                if (i == 2) {
                    set.add(5);
                } else if (i == 5) {
                    set.add(2);
                } else if (i == 6) {
                    set.add(6);
                } else if (i == 9) {
                    set.add(9);
                }
            }


        }
    }

}
